package com.bookmall.cart.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bookmall.common.utils.MyQuery;
import com.bookmall.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.bookmall.cart.domain.OrderPaymentInfo;
import com.bookmall.cart.service.IOrderPaymentInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 支付信息Controller
 *
 * @author huyulu
 * @date 2022-04-21
 */
@RestController
@RequestMapping("/order/pay")
public class OrderPaymentInfoController extends BaseController
{
    @Autowired
    private IOrderPaymentInfoService orderPaymentInfoService;

    /**
     * 查询支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:pay:list')")
    @GetMapping("/list")
    public AjaxResult list(OrderPaymentInfo orderPaymentInfo)
    {
        IPage<OrderPaymentInfo> page = orderPaymentInfoService.page(new MyQuery<OrderPaymentInfo>().getPage(orderPaymentInfo), new QueryWrapper<>(orderPaymentInfo));
        PageUtils pageUtils = new PageUtils(page);
        return AjaxResult.success(pageUtils);
    }

    /**
     * 导出支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:pay:export')")
    @Log(title = "支付信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderPaymentInfo orderPaymentInfo)
    {
        List<OrderPaymentInfo> list = orderPaymentInfoService.list(new QueryWrapper<>(orderPaymentInfo));
        ExcelUtil<OrderPaymentInfo> util = new ExcelUtil<OrderPaymentInfo>(OrderPaymentInfo.class);
        util.exportExcel(response, list, "支付信息数据");
    }

    /**
     * 获取支付信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:pay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(orderPaymentInfoService.getById(id));
    }

    /**
     * 新增支付信息
     */
    @PreAuthorize("@ss.hasPermi('order:pay:add')")
    @Log(title = "支付信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderPaymentInfo orderPaymentInfo)
    {
        return toAjax(orderPaymentInfoService.save(orderPaymentInfo));
    }

    /**
     * 修改支付信息
     */
    @PreAuthorize("@ss.hasPermi('order:pay:edit')")
    @Log(title = "支付信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderPaymentInfo orderPaymentInfo)
    {
        return toAjax(orderPaymentInfoService.updateById(orderPaymentInfo));
    }

    /**
     * 删除支付信息
     */
    @PreAuthorize("@ss.hasPermi('order:pay:remove')")
    @Log(title = "支付信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(orderPaymentInfoService.removeBatchByIds(ids));
    }
}
